package com.ruoyi.project.module.by.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.by.domain.By;
import com.ruoyi.project.module.by.service.IByService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 软件管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-20
 */
@Controller
@RequestMapping("/module/by")
public class ByController extends BaseController
{
    private String prefix = "module/by";
	
	@Autowired
	private IByService byService;
	
	@RequiresPermissions("module:by:view")
	@GetMapping()
	public String by()
	{
	    return prefix + "/by";
	}
	
	/**
	 * 查询软件管理列表
	 */
	@RequiresPermissions("module:by:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(By by)
	{
		startPage();
        List<By> list = byService.selectByList(by);
		return getDataTable(list);
	}
	
	/**
	 * 新增软件管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存软件管理
	 */
	@RequiresPermissions("module:by:add")
	@Log(title = "软件管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(By by)
	{		
		return toAjax(byService.insertBy(by));
	}

	/**
	 * 修改软件管理
	 */
	@GetMapping("/edit/{iD}")
	public String edit(@PathVariable("iD") Integer iD, ModelMap mmap)
	{
		By by = byService.selectByById(iD);
		mmap.put("by", by);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存软件管理
	 */
	@RequiresPermissions("module:by:edit")
	@Log(title = "软件管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(By by)
	{		
		return toAjax(byService.updateBy(by));
	}
	
	/**
	 * 删除软件管理
	 */
	@RequiresPermissions("module:by:remove")
	@Log(title = "软件管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(byService.deleteByByIds(ids));
	}
	
}
